#!/bin/bash
########################################
# 使用溢出检测工具启动若依项目示例
########################################

echo ""
echo "========================================"
echo "  带溢出检测的若依项目启动脚本"
echo "========================================"
echo ""

# 获取脚本所在目录
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# 设置Agent路径
DETECTOR_JAR="$SCRIPT_DIR/../target/overflow-detector-1.0.0.jar"

# 检查Agent是否存在
if [ ! -f "$DETECTOR_JAR" ]; then
    echo "[错误] 检测工具未构建，请先执行:"
    echo "       cd overflow-detector-tool"
    echo "       mvn clean package"
    exit 1
fi

# 设置若依项目路径
RUOYI_JAR="$SCRIPT_DIR/../../ruoyi-admin/target/ruoyi-admin.jar"

# 检查若依项目是否存在
if [ ! -f "$RUOYI_JAR" ]; then
    echo "[错误] 若依项目未构建，请先执行:"
    echo "       mvn clean package"
    exit 1
fi

echo "[信息] Agent路径: $DETECTOR_JAR"
echo "[信息] 项目路径: $RUOYI_JAR"
echo ""

# 配置检测参数
JAVA_OPTS="-javaagent:$DETECTOR_JAR"
JAVA_OPTS="$JAVA_OPTS -Doverflow.packages=com.ruoyi"
JAVA_OPTS="$JAVA_OPTS -Doverflow.threshold=0.7"
JAVA_OPTS="$JAVA_OPTS -Doverflow.logfile=overflow-monitor.log"
JAVA_OPTS="$JAVA_OPTS -Doverflow.maxWarnings=5"

echo "[信息] 启动参数: $JAVA_OPTS"
echo ""
echo "[提示] 日志将保存到: overflow-monitor.log"
echo "[提示] 按 Ctrl+C 停止服务"
echo ""

# 启动项目
java $JAVA_OPTS -jar "$RUOYI_JAR"
